// pages/index/imageChange.js
var app = getApp()
Page({
  data: {
    ballleft: -20,
    screenWidth: 0,
  },
  onLoad: function () {
    var _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          screenHeight: res.windowHeight,
          screenWidth: res.windowWidth,
        });
      }
    });

  },
  ballMoveEvent: function (e) {
    var touchs = e.touches[0];
    var pageX = touchs.pageX;
    console.log('宽度 ' + this.data.screenWidth)
    console.log('pageX: ' + pageX);
    //这里用right和bottom.所以需要将pageX pageY转换  
    var x = this.data.screenWidth / 2 - pageX - 20;
    if (this.data.screenWidth > 385) {
      if (x > 42) { x = 42; }
    } else {
      if (x > 32) { x = 32; }
    }
    if (x < 0) { x = 0; }
    console.log('x:' + x)
    this.setData({
      ballleft: -x
    });
  }
}) 